
#[macro_export]
macro_rules! lavender_query_filter {
        (@eq $field:tt $value:tt) => {
            $crate::db::query_statement::WhereSqlMaker::eq($field,$value)
        };
        (@not_eq $field:tt $value:tt) => {
            $crate::db::query_statement::WhereSqlMaker::not_eq($field,$value)
        }; 
        (@lt $field:tt $value:tt) => {
            $crate::db::query_statement::WhereSqlMaker::lt($field,$value)
        };
        (@lte $field:tt $value:tt) => {
            $crate::db::query_statement::WhereSqlMaker::lte($field,$value)
        };
        (@gt $field:tt $value:tt) => {
            $crate::db::query_statement::WhereSqlMaker::gt($field,$value)
        };
        (@gte $field:tt $value:tt) => {
            $crate::db::query_statement::WhereSqlMaker::gte($field,$value)
        };
        (@range $field:tt $lv:tt $gv:tt) => {
            {
                let q1 = lavender_query_filter!(@lt $field $lv);
                let q2 = lavender_query_filter!(@gt $field $gv);
                $crate::db::query_statement::WhereSqlMaker::link_and(vec![q1,q2])
            }        
        };
        (@range_en $field:tt $lv:tt $gv:tt) => {
            {
                let q1 = lavender_query_filter!(@lte $field $lv);
                let q2 = lavender_query_filter!(@gt $field $gv);
                $crate::db::query_statement::WhereSqlMaker::link_and(vec![q1,q2])            
            }  
        };
        (@range_ee $field:tt $lv:tt $gv:tt) => {
            {
                let q1 = lavender_query_filter!(@lte $field $lv);
                let q2 = lavender_query_filter!(@gte $field $gv);
                $crate::db::query_statement::WhereSqlMaker::link_and(vec![q1,q2])               
            }  
        };
        (@range_ne $field:tt $lv:tt $gv:tt) => {
            {
                let q1 = lavender_query_filter!(@lt $field $lv);
                let q2 = lavender_query_filter!(@gte $field $gv);
                $crate::db::query_statement::WhereSqlMaker::link_and(vec![q1,q2])                 
            }  
        };
        (@like $field:tt $value:tt) => {
            $crate::db::query_statement::WhereSqlMaker::like($field,$value,$crate::db::query_statement::WhereLikeOp::None)
        };
        (@like_l $field:tt $value:tt) => {
            $crate::db::query_statement::WhereSqlMaker::like($field,$value,$crate::db::query_statement::WhereLikeOp::Left)
        };
        (@like_r $field:tt $value:tt) => {
            $crate::db::query_statement::WhereSqlMaker::like($field,$value,$crate::db::query_statement::WhereLikeOp::Right)
        };
        (@like_a $field:tt $value:tt) => {
            $crate::db::query_statement::WhereSqlMaker::like($field,$value,$crate::db::query_statement::WhereLikeOp::Both)
        };
        (@in_ $field:tt $($value:tt)+ ) => {
            {
                let mut list:Vec<$crate::db::query_statement::SqlMakerBindValue> = vec![];
                $({
                    list.push($value.into());
                })+;
                lavender_query_filter!(@in_list $field list)
            }
        };
        (@not_in $field:tt  $($value:tt)+ ) => {
            {
                let mut list:Vec<$crate::db::query_statement::SqlMakerBindValue> = vec![];
                $({
                    list.push($value.into());
                })+;
                lavender_query_filter!(@not_in_list $field list)
            }
        };
        (@in_list $field:tt $value:tt ) => {
            {
                let mut list:Vec<$crate::db::query_statement::SqlMakerBindValue> = vec![];
                $value.into_iter().all(|item|{
                    list.push(item.into());
                    true
                });
                $crate::db::query_statement::WhereSqlMaker::in_set($field,list)
            }
        };
        (@not_in_list $field:tt $value:tt ) => {
            {
                let mut list:Vec<$crate::db::query_statement::SqlMakerBindValue> = vec![];
                $value.into_iter().all(|item|{
                    list.push(item.into());
                    true
                });
                $crate::db::query_statement::WhereSqlMaker::not_in_set($field,list)
            }
        };
    
        (@null $field:tt ) => {       
            $crate::db::query_statement::WhereSqlMaker::null($field)        
        };
    
        (@not_null $field:tt ) => {       
            $crate::db::query_statement::WhereSqlMaker::not_null($field)        
        };
    
        (@literal $field:tt ) => {       
            $crate::db::query_statement::WhereSqlMaker::with($field)        
        };
    
        ($field:tt <> $value:tt) => {
            lavender_query_filter!(@not_eq $field $value)
        };
        ($field:tt != $value:tt) => {
            lavender_query_filter!(@not_eq $field $value)
        };
        ($field:tt = $value:tt) => {
            lavender_query_filter!(@eq $field $value)
        };
        ($field:tt > $value:tt) => {
            lavender_query_filter!(@gt $field $value)
        };
        ($field:tt >= $value:tt) => {
            lavender_query_filter!(@gte $field $value)
        };
        ($field:tt < $value:tt) => {
            lavender_query_filter!(@lt $field $value)
        };
        ($field:tt <= $value:tt) => {
            lavender_query_filter!(@lte $field $value)
        };
        (range $field:tt $lv:tt $gv:tt) => {
            lavender_query_filter!(@range $field $lv $gv)
        };
        (range_ne $field:tt $lv:tt $gv:tt) => {
            lavender_query_filter!(@range_ne $field $lv $gv)
        };
        (range_en $field:tt $lv:tt $gv:tt) => {
            lavender_query_filter!(@range_en $field $lv $gv)
        };
        (range_ee $field:tt $lv:tt $gv:tt) => {
            lavender_query_filter!(@range_ee $field $lv $gv)
        };
    
        (null $field:tt) => {
            lavender_query_filter!(@null $field)
        };
    
        ($field:tt null) => {
            lavender_query_filter!(@null $field)
        };
    
        (not_null $field:tt) => {
            lavender_query_filter!(@not_null $field)
        };
    
        (literal $field:tt) => {
            lavender_query_filter!(@literal $field)
        };
    
        ($field:tt not_null) => {
            lavender_query_filter!(@not_null $field)
        };
    
        ($field:tt > $value:tt) => {
            lavender_query_filter!(@gt $field $value)
        };

        ($field:tt >= $value:tt) => {
            lavender_query_filter!(@gte $field $value)
        };

        ($field:tt < $value:tt) => {
            lavender_query_filter!(@lt $field $value)
        };

        ($field:tt <= $value:tt) => {
            lavender_query_filter!(@lte $field $value)
        };

        ($field:tt != $value:tt) => {
            lavender_query_filter!(@not_eq $field $value)
        };

        ($field:tt <> $value:tt) => {
            lavender_query_filter!(@not_eq $field $value)
        };

        ($field:tt = $value:tt) => {
            lavender_query_filter!(@eq $field $value)
        };

        ($field:tt == $value:tt) => {
            lavender_query_filter!(@eq $field $value)
        };
    
        ($field:tt like $value:tt) => {
            lavender_query_filter!(@like $field $value)
        };
        ($field:tt like % $value:tt) => {
            lavender_query_filter!(@like_l $field $value)
        };
    
        ($field:tt like $value:tt %) => {
            lavender_query_filter!(@like_r $field $value)
        };
    
        ($field:tt like % $value:tt %) => {
            lavender_query_filter!(@like_a $field $value)
        };
    
        ($field:tt in_ $($value:tt)+ ) => {
            lavender_query_filter!(@in_ $field $($value)+)
        };
    
        ($field:tt in_list $value:tt ) => {
            lavender_query_filter!(@in_list $field $value)
        };
    
        ($field:tt not_in $($value:tt)+ ) => {
            lavender_query_filter!(@not_in $field $($value)+)
        };
    
        ($field:tt not_in_list $value:tt ) => {
            lavender_query_filter!(@not_in_list $field $value)
        };
    
        ($cat:tt $field:tt $value:tt) => {
            lavender_query_filter!(@$cat $field $value)
        };
        ($field:tt $value:tt) => {
            lavender_query_filter!(@eq $field $value)
        };
        ($field:tt) => {
            lavender_query_filter!(@literal $field)
        };
        () => {
            $crate::db::query_statement::WhereSqlMaker::default()
        }
    }
    

#[macro_export]
macro_rules! lavender_query_filters {
        ($( { $($item:tt)+ } ),+) => {
            {
                let mut filters =  vec![];
                $(            
                    filters.push(lavender_query_filter!($($item)+));
                )+
                $crate::db::query_statement::WhereSqlMaker::link_and(filters)
            }
            
        };
}

#[macro_export]
macro_rules! lavender_query_filter_or {
        ($( { $($item:tt)+ } ),+) => {
            {
                let mut filters =  vec![];
                $(            
                    filters.push(lavender_query_filter!($($item)+));
                )+
                $crate::db::query_statement::WhereSqlMaker::link_or(filters)
            }            
        };
}

#[macro_export]     
macro_rules! lavender_query_key_values {
    (@inner $maker:tt $col:tt literal $val:tt) => {
        {
            $maker.push_key_value_literal($col,$val)
        }
        
    };
    (@inner $maker:tt $col:tt $val:tt) => {
        {
            $maker.push_key_value($col,$val)
        }        
    };
    ($( { $($item:tt)+ } ),+ ) => {
        {    
            let mut maker  =  $crate::db::query_statement::ColumnSqlMaker::default();
            $(
                lavender_query_key_values!(@inner maker $($item)+);
            )+;
            maker
        }
    };
}

#[macro_export]     
macro_rules! lavender_query_fields {
    ($($item:tt),+ ) => {
        {   
            let mut list = vec![];
            $(
                list.push($item);
            )+;
            $crate::db::query_statement::ColumnSqlMaker::with_keys(list)
        }
    };
}



